<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>escape</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
<link rel="home" href="index.html" title="Smarty 3 Manual">
<link rel="up" href="language.modifiers.html" title="Chapter 5. Variable Modifiers">
<link rel="prev" href="language.modifier.default.html" title="default">
<link rel="next" href="language.modifier.from_charset.html" title="from_charset">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<div class="navheader">
<table width="100%" summary="Navigation header">
<tr><th colspan="3" align="center">escape</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="language.modifier.default.html">Prev</a> </td>
<th width="60%" align="center">Chapter 5. Variable Modifiers</th>
<td width="20%" align="right"> <a accesskey="n" href="language.modifier.from_charset.html">Next</a>
</td>
</tr>
</table>
<hr>
</div>
<div class="sect1" title="escape">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="language.modifier.escape"></a>escape</h2></div></div></div>
<p>
    <code class="varname">escape</code> is used to encode or escape a variable to <code class="literal">html</code>,
     <code class="literal">url</code>, <code class="literal">single quotes</code>,
     <code class="literal">hex</code>, <code class="literal">hexentity</code>,
     <code class="literal">javascript</code> and <code class="literal">mail</code>.
     By default its <code class="literal">html</code>.
  </p>
<div class="informaltable"><table border="1">
<colgroup>
<col align="center">
<col align="center">
<col align="center">
<col align="center">
<col align="center">
<col>
</colgroup>
<thead><tr>
<th align="center">Parameter Position</th>
<th align="center">Type</th>
<th align="center">Required</th>
<th align="center">Possible Values</th>
<th align="center">Default</th>
<th>Description</th>
</tr></thead>
<tbody>
<tr>
<td align="center">1</td>
<td align="center">string</td>
<td align="center">No</td>
<td align="center">
<code class="literal">html</code>, <code class="literal">htmlall</code>,
              <code class="literal">url</code>,
               <code class="literal">urlpathinfo</code>, <code class="literal">quotes</code>,
               <code class="literal">hex</code>, <code class="literal">hexentity</code>,
               <code class="literal">javascript</code>, <code class="literal">mail</code>
       </td>
<td align="center"><code class="literal">html</code></td>
<td>This is the escape format to use.</td>
</tr>
<tr>
<td align="center">2</td>
<td align="center">string</td>
<td align="center">No</td>
<td align="center">
<code class="literal">ISO-8859-1</code>, <code class="literal">UTF-8</code>,
      and any character set supported by
      <a class="ulink" href="http://php.net/htmlentities" target="_top">
      <code class="varname">htmlentities()</code></a>
      </td>
<td align="center"><code class="literal">UTF-8</code></td>
<td>The character set encoding passed to htmlentities() et. al.</td>
</tr>
<tr>
<td align="center">3</td>
<td align="center">boolean</td>
<td align="center">No</td>
<td align="center"><code class="constant">FALSE</code></td>
<td align="center"><code class="constant">TRUE</code></td>
<td>Double encode entites from &amp;amp; to &amp;amp;amp; (applys to <code class="literal">html</code> and <code class="literal">htmlall</code> only)</td>
</tr>
</tbody>
</table></div>
<div class="example">
<a name="id352954"></a><p class="title"><b>Example 5.10. escape</b></p>
<div class="example-contents">
<pre class="programlisting">

&lt;?php

$smarty-&gt;assign('articleTitle',
                "'Stiff Opposition Expected to Casketless Funeral Plan'"
                );
$smarty-&gt;assign('EmailAddress','smarty@example.com');

?&gt;

   </pre>
<p>
   These are example <code class="literal">escape</code> template lines followed by the output
   </p>
<pre class="programlisting">

{$articleTitle}
'Stiff Opposition Expected to Casketless Funeral Plan'

{$articleTitle|escape}
&amp;#039;Stiff Opposition Expected to Casketless Funeral Plan&amp;#039;

{$articleTitle|escape:'html'}    {* escapes  &amp; " ' &lt; &gt; *}
&amp;#039;Stiff Opposition Expected to Casketless Funeral Plan&amp;#039;

{$articleTitle|escape:'htmlall'} {* escapes ALL html entities *}
&amp;#039;Stiff Opposition Expected to Casketless Funeral Plan&amp;#039;

&lt;a href="?title={$articleTitle|escape:'url'}"&gt;click here&lt;/a&gt;
&lt;a
href="?title=%27Stiff%20Opposition%20Expected%20to%20Casketless%20Funeral%20Plan%27"&gt;click here&lt;/a&gt;

{$articleTitle|escape:'quotes'}
\'Stiff Opposition Expected to Casketless Funeral Plan\'

&lt;a href="mailto:{$EmailAddress|escape:"hex"}"&gt;{$EmailAddress|escape:"hexentity"}&lt;/a&gt;
{$EmailAddress|escape:'mail'}    {* this converts to email to text *}
&lt;a href="mailto:%62%6f%..snip..%65%74"&gt;&amp;#x62;&amp;#x6f;&amp;#x62..snip..&amp;#x65;&amp;#x74;&lt;/a&gt;

{'mail@example.com'|escape:'mail'}
smarty [AT] example [DOT] com

   </pre>
</div>
</div>
<br class="example-break"><div class="example">
<a name="id352985"></a><p class="title"><b>Example 5.11. Other examples</b></p>
<div class="example-contents">
<pre class="screen">

{* the "rewind" paramater registers the current location *}
&lt;a href="$my_path?page=foo&amp;rewind=$my_uri|urlencode}"&gt;click here&lt;/a&gt;

   </pre>
<p>This snippet is useful for emails, but see also
      <a class="link" href="language.function.mailto.html" title="{mailto}">
      <code class="varname">{mailto}</code></a></p>
<pre class="screen">

{* email address mangled *}
&lt;a href="mailto:{$EmailAddress|escape:'hex'}"&gt;{$EmailAddress|escape:'mail'}&lt;/a&gt;

   </pre>
</div>
</div>
<br class="example-break"><p>
   See also
   <a class="link" href="language.escaping.html" title="Escaping Smarty Parsing">escaping smarty parsing</a>,
   <a class="link" href="language.function.mailto.html" title="{mailto}"><code class="varname">{mailto}</code></a>
   and the
   <a class="link" href="tips.obfuscating.email.html" title="Obfuscating E-mail Addresses">obfuscating email addresses</a> page.
  </p>
</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="language.modifier.default.html">Prev</a> </td>
<td width="20%" align="center"><a accesskey="u" href="language.modifiers.html">Up</a></td>
<td width="40%" align="right"> <a accesskey="n" href="language.modifier.from_charset.html">Next</a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">default </td>
<td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td>
<td width="40%" align="right" valign="top"> from_charset</td>
</tr>
</table>
</div>
</body>
</html>
